package com.example.demo01.service;

import com.example.demo01.mapper.FormInfoMapper;
import com.example.demo01.mapper.UserMapper;
import com.example.demo01.pojo.FormInfo;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.annotation.Schedules;
import org.springframework.stereotype.Service;

import java.util.List;
//如果用@Scheduled，实现InitializingBean接口
@Service
public class FormInfoService {
    @Autowired
    private FormInfoMapper formInfoMapper;


    public List<FormInfo> getAllFormInfos(){
        return formInfoMapper.getAllFormInfos();
    }

    public FormInfo getFormInfoByName(String username) {
        FormInfo formInfo = formInfoMapper.getFormInfoByName(username);
        return formInfo;
    }

    public void updateFormInfo(FormInfo formInfo) {
        formInfoMapper.updateFormInfo(formInfo);
    }

    //今天未打卡名单
    public List<FormInfo> getNoPostUsersToday() {
        return formInfoMapper.getNoPostUsersToday();
    }


    public void addFormInfo(FormInfo formInfo){
        formInfoMapper.addFormInfo(formInfo);
    }

//    @Override
//    public void afterPropertiesSet() throws Exception {
//        updateEveryday();
//    }
//
//    @Scheduled(cron = "0 0 1 * * *")//每日凌晨1点更新form_info表中的 isPostToday字段，将所有的isPostToday修改成 “否”
//    public void updateEveryday(){
//        List<FormInfo> formInfos=formInfoMapper.getAllFormInfos();
//
//        for(FormInfo f:formInfos){
//            formInfoMapper.updateIsPostToday(f.getUsername());
//        }
//
//    }

}
